package sample;
import javafx.application.*;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;


public class Main extends Application{
    TextArea Text;
    @Override
    public void start(Stage primaryStage)
    {
        Text = new TextArea();
        Text.setWrapText(true);
        Button start = new Button("Start");
        FlowPane pane = new FlowPane();
        pane.setAlignment(Pos.CENTER);
        pane.setVgap(10);
        pane.setPadding(new Insets(10));
        pane.getChildren().addAll(Text,start);
        Scene scene = new Scene(pane);
        primaryStage.setTitle("多线程示例");
        primaryStage.setScene(scene);


        primaryStage.show();
/*



        Runnable PrintA = new PrintChar('A',10000,Text);
        Runnable PrintB = new PrintChar('B',10000,Text);
        Runnable Print100 = new PrintNum<Integer>(520,10000,Text);

        Thread t1 = new Thread(PrintA);
        Thread t2 = new Thread(PrintB);
        Thread t3 = new Thread(Print100);

        t1.start();
        t2.start();
        t3.start();
        */
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Application.launch(args);

    }
}

class PrintChar implements Runnable{
    private char charToPrint;
    private int times;
    private TextArea Text;
    public PrintChar(char charToPrint,int times, TextArea Text){
        this.charToPrint = charToPrint;
        this.times = times;
        this.Text = Text;
    }
    @Override
    public void run() {
        for (int i = 0; i < times; i++) {
            Text.appendText(""+charToPrint);


        }
    }
}
class PrintNum<T extends Number> implements Runnable{
    private T NumToPrint;
    private int times;
    private TextArea Text;
    public PrintNum(T numToPrint,int times,TextArea Text){
        this.NumToPrint = numToPrint;
        this.times = times;
        this.Text = Text;
    }
    @Override
    public void run(){
        for(int i = 0; i < times; i++){
            Text.appendText(""+NumToPrint);

        }
    }
}
